define(function(require,exports,module){

	//检测类
	var Auth = require('qd-auth-1.0');

	$(".bingPhoneBtnC").click(function(){
		$("#hidbankno").val($(this).next().val());
		$("#bankcardBindMobile").find("form")[0].reset();
		returnflag = false;
		window.layer.open({
			type: 1,
			closeBtn: 1,
	        title: "系统升级，请验证该银行卡预留手机号！",
			area: ['450px', '245px'],
			border: [1, 1, '#cecfd0'],
			content: $("#bankcardBindMobile"),
			cancel:function(){
				returnflag = true;
			}
		});	
	});
	$(".deletePhoneBtnC").click(function(){
		window.layer.open({
			type: 1,
			closeBtn: 1,
	        title: "解绑请先输入手机验证码！",
			area: ['450px', '245px'],
			border: [1, 1, '#cecfd0'],
			content: $("#deletebankcardMobile"),
			cancel:function(){
				returnflag = true;
			}
		});	
	});
	$("#bankcardDelMobileBtn1").click(function(){
		returnflag = false;
		get_code_time(this);
		$.ajax({
			url:"/tpp/tppSinaAction/sendUnBindBankCode.html",
			type:"post",
			dataType:"json",
			success: function(data){
				if(data.result==false){
					returnflag = true;
				}
				if(data.msg!=undefined){
					layer.alert(data.msg);					
				}
			}
		});
	});
	
	/**/
	var wait = 60;
	var returnflag = false;
	get_code_time = function (elem) {
		if (wait == 0 ||returnflag==true) {
			$(elem).val("重新发送");
			$(elem).removeClass("addCardVaildCodeDis");
			$(elem).attr("disabled",false);
			wait = 60;
		} else {
			$(elem).val("("+wait+")秒后重新获取");
			$(elem).addClass("addCardVaildCodeDis");
			$(elem).attr("disabled",true);
			wait--;
			setTimeout(function() {
				get_code_time(elem);
			}, 1000);
		}
	};
	$("#bankcardBindMobileBtn1").click(function(){
		if(!/^1[3578]\d{9}$/.test($("#mobilephone").val())){
    		layer.alert('请正确填写手机号码');
			return false;
		}
		returnflag = false;
		get_code_time(this);
		
		$.ajax({
			url:"/member/card/phone.html?mobilePhone="+$("#mobilephone").val()+"&bankNo="+$("#hidbankno").val(),
			type:"post",
			dataType:"json",
			success: function(data){
				if(data.result==false){
					returnflag = true;
				}
				if(data.msg!=undefined){
					layer.alert(data.msg);					
				}
			}
		});
	});
	$("#bankcardBindMobileBtn2").click(function(){
		if($("#code").val()==""){
    		layer.alert('请输入手机验证码');
			return false;
		}
		$.ajax({
			url:$(this).attr("data-src")+"?validCode="+$("#code").val(),
			type:"post",
			dataType:"json",
			success: function(data){
				if(data.result==true){
					layer_new("",2,{time:3000,msg:"手机号验证成功"},function(){
						window.location.reload();
					}); 
				}else{
					layer_new("",1,{msg:data.msg}); 
				}
			}
		});
	});
	
	/*/member/card/phone
	/member/card/phone/advance*/

	//判断是否已认证或开通第三方接口
	$.ajax({
		url:"/member/useridentify/realNameStatus.html?randomTime=" + (new Date()).getTime(),
		type:"get",
		dataType:"json",
		success:function(data){
			if(data.result==false){
				layer_new("",1,{msg:"您还未实名认证，请先认证！"},function(){
					window.location.href = "/member/security/setting.html";
				}); 
			}
		}
	});
	//银行卡号解绑	
	$(".cardList").delegate("#resetBank","click",function(){
		var re_url = $(this).attr("data-value");
		$("body").undelegate(".okBtn_unbind","click").delegate(".okBtn_unbind","click",function(){
			layer.closeAll();
			$.ajax({
				url:re_url,
				type:"post",
				success: function(data){
					//单点登录检测
					var errorCode = data.err_code || "";
	                if(errorCode === "E0001") {
	                	if(Auth.checkLogin(arguments[0]) == false) {return ;}
	                }

					if(data.result){
						layer.closeAll();
						layer_new("",2,{time:3000,msg:"解除绑定银行卡成功"},function(){
							window.location.reload();
						}); 
					}else{
						layer.closeAll();
						layer_new("",1,{msg:data.msg}); 
						$(".failBtn").click(function(){
							layer.closeAll();
						});
					}						
				}			
			});		
		});
			//构造确认框DOM
		layer_new("",4,{msg:"确定解除绑定这张银行卡？"}); 
	});
	
	
});